package com.softer.wxzj.controller;

import com.github.pagehelper.PageInfo;
import com.softer.wxzj.common.aop.annotation.LogRecord;
import com.softer.wxzj.common.aop.enums.LogOperationType;
import com.softer.wxzj.common.aop.enums.LogOperationUnit;
import com.softer.wxzj.common.entity.CommonResult;
import com.softer.wxzj.common.entity.Page;
import com.softer.wxzj.entity.BaseBuildInfo;
import com.softer.wxzj.entity.BaseModifyDetail;
import com.softer.wxzj.mapper.SysCoreParamMapper;
import com.softer.wxzj.service.BaseBuildInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * BaseBuildInfoController class
 *
 * @author zcz
 * @date 2019/4/10
 */
@RestController
@RequestMapping("/baseBuildInfo")
@Slf4j
public class BaseBuildInfoController {
    @Autowired
    BaseBuildInfoService baseBuildInfoService;
    @Autowired
    SysCoreParamMapper sysCoreParamMapper;

    @RequestMapping("/add")
    @LogRecord(description = "自然幢添加", operationUnit = LogOperationUnit.BASE_BUILD_INFO, operationType = LogOperationType.INSERT)
    public CommonResult add(@RequestBody BaseBuildInfo baseBuildInfo) {
        return baseBuildInfoService.insert(baseBuildInfo);
    }

    /**
     * 楼栋修改
     *
     * @param baseBuildInfo
     * @return
     */
    @RequestMapping("/update")
    @LogRecord(description = "楼栋修改", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.UPDATE)
    public CommonResult update(@RequestBody BaseBuildInfo baseBuildInfo) {
        return baseBuildInfoService.update(baseBuildInfo);
    }

    /**
     * 楼栋删除
     *
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    @LogRecord(description = "楼栋删除", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.DELETE)
    public CommonResult delete(String id) {
        return baseBuildInfoService.delete(id);
    }

    /**
     * 自然幢信息
     *
     * @param page
     * @param baseBuildInfo
     * @return
     */
    @RequestMapping("/getList")
    @LogRecord(description = "自然幢信息", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.SELECT)
    public PageInfo<BaseBuildInfo> getList(Page page, BaseBuildInfo baseBuildInfo) {
        return baseBuildInfoService.getList(page, baseBuildInfo);
    }

    /**
     * 外网获取自然幢列表
     *
     * @param regionId 小区ID
     * @return 自然幢列表
     */
    @PostMapping("/getOuterNetBuildList")
    public PageInfo<BaseBuildInfo> getOuterNetBuildList(Page page, String regionId) {
        return baseBuildInfoService.getOuterNetBuildList(page, regionId);
    }

    /**
     * 模糊查询自然幢信息列表
     *
     * @param page      分页实体
     * @param param     模糊查询参数
     * @param flowState 状态
     * @return 自然幢信息
     */
    @RequestMapping("/fuzzySearch")
    @LogRecord(description = "模糊查询自然幢信息列表", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.SELECT)
    public PageInfo<BaseBuildInfo> fuzzySearch(Page page, String param, String flowState, String no) {
        return baseBuildInfoService.fuzzySearch(page, param, flowState, no);
    }

    /**
     * 自然幢信息单个
     *
     * @param id      自然幢ID
     * @param arcType 图档大类
     * @return
     */
    @RequestMapping("/getInfo")
    @LogRecord(description = "自然幢信息单个", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.SELECT)
    public BaseBuildInfo getInfo(String id, String arcType) {
        return baseBuildInfoService.getInfoById(id, arcType);
    }

    /**
     * 自然幢保存中间表
     *
     * @param baseBuildInfo
     * @return
     */
    @RequestMapping("/updateToSave")
    @LogRecord(description = "自然幢保存中间表", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.SELECT)
    public CommonResult updateToSave(@RequestBody BaseBuildInfo baseBuildInfo) throws Exception {
        return baseBuildInfoService.updateToSave(baseBuildInfo);
    }

    /**
     * 自然幢审核列表查询
     *
     * @param baseBuildInfo
     * @return
     */
    @RequestMapping("/getAuditList")
    @LogRecord(description = "自然幢审核列表查询", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.SELECT)
    public PageInfo<BaseBuildInfo> getAuditList(Page page, BaseBuildInfo baseBuildInfo, String flowType) {
        return baseBuildInfoService.getAuditList(page, baseBuildInfo, flowType);
    }

    /**
     * 模糊查询自然幢审核列表
     *
     * @param baseBuildInfo 查询实体
     * @return 待审核列表
     */
    @RequestMapping("/fuzzyAuditList")
    @LogRecord(description = "模糊查询自然幢审核列表", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.SELECT)
    public PageInfo<BaseBuildInfo> fuzzyAuditList(Page page, BaseBuildInfo baseBuildInfo) {
        return baseBuildInfoService.fuzzyAuditList(page, baseBuildInfo);
    }

    /**
     * 添加审核
     *
     * @param id      业务ID
     * @param opinion 审核意见
     * @param mark    审批通过 audit_pass
     *                审批否决 audit_veto
     *                审批退回 audit_back
     * @return 审核结果
     */
    @RequestMapping("/addAudit")
    @LogRecord(description = "添加审核", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.UPDATE)
    public CommonResult audit(@RequestParam("id") String id, String opinion, @RequestParam("mark") String mark) {
        return baseBuildInfoService.addAudit(id, opinion, mark);
    }

    /**
     * 自然幢变更审核
     * BaseModifyReq 根据id 更改变更原因（追加）
     * 在终审结束时 更改当前的 flow_state 的状态 同意  拒绝
     * 更改业务表 base_owner_committee 的基本信息
     *
     * @param id      业务记录 id（前端传）
     * @param opinion 前端传值 原因
     * @param mark    前端传值 同意拒绝
     * @return
     */
    @RequestMapping("/changeResidentialCommittee")
    @LogRecord(description = "自然幢变更审核", operationUnit = LogOperationUnit.Base_Owner_Committee, operationType = LogOperationType.UPDATE)
    public CommonResult changeResidentialCommittee(String id, String opinion, String mark) {
        return baseBuildInfoService.changeResidentialCommittee(id, opinion, mark);
    }

    /**
     * 自然幢添加提交
     *
     * @param id
     * @return
     */
    @RequestMapping("/insertSaveAndSubmit")
    @LogRecord(description = "自然幢添加提交", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.SELECT)
    public CommonResult insertSaveAndSubmit(String id) {
        return baseBuildInfoService.insertSaveAndSubmit(id);
    }

    /**
     * 根据小区ID模糊查询自然幢信息列表
     *
     * @param page      分页实体
     * @param param     模糊查询参数
     * @param id        小区ID
     * @param flowState 状态
     * @return 自然幢信息
     */
    @RequestMapping("/fuzzySearchByRegionId")
    @LogRecord(description = "模糊查询自然幢信息列表", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.SELECT)
    public PageInfo<BaseBuildInfo> fuzzySearchByRegionId(Page page, String param, String id, String flowState) {
        return baseBuildInfoService.fuzzySearchByRegionId(page, param, id, flowState);
    }

    /**
     * 检查自然幢名是否重复
     *
     * @param buildName
     * @param regionNo
     * @return
     */
    @RequestMapping("/checkBuildName")
    @LogRecord(description = "自然幢名称重复验证", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.SELECT)
    public CommonResult checkBuildName(@RequestParam("buildName") String buildName, @RequestParam("regionNo") String regionNo, String id) {
        return baseBuildInfoService.checkBuildName(buildName, regionNo, id);
    }

    /**
     * 查询业主销户自然幢信息
     *
     * @param baseBuildInfo
     * @return
     */
    @RequestMapping("/getListAndOwnerOut")
    @LogRecord(description = "查询业主销户自然幢信息", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.SELECT)
    public List<BaseBuildInfo> getListAndOwnerOut(BaseBuildInfo baseBuildInfo) {
        return baseBuildInfoService.getListAndOwnerOut(baseBuildInfo);
    }

    @RequestMapping("/getListToBatchRef")
    @LogRecord(description = "自然幢信息", operationUnit = LogOperationUnit.BASE_BUILE_INFO, operationType = LogOperationType.SELECT)
    public PageInfo<BaseBuildInfo> getListToBatchRef(Page page, BaseBuildInfo baseBuildInfo) {
        return baseBuildInfoService.getListToBatchRef(page, baseBuildInfo);
    }

    /**
     * 根据小区ID查询自然幢列表
     *
     * @param regionId    小区ID
     * @param subRegionId 分区ID
     * @return 自然幢列表
     */
    @PostMapping("/getBuildList")
    public List<BaseBuildInfo> getBuildList(String regionId, String subRegionId) {
        return baseBuildInfoService.getBuildList(regionId, subRegionId);
    }

    /**
     * 根据id查询变更详情
     *
     * @param id 变更类型id
     * @return
     */
    @RequestMapping("/getModifyDetailList")
    @LogRecord(description = "根据id查询变更详情", operationUnit = LogOperationUnit.BASE_REGION_INFO, operationType = LogOperationType.SELECT)
    public PageInfo<BaseModifyDetail> getModifyDetailList(Page page, String id) {
        return baseBuildInfoService.getModifyDetailList(page, id);
    }

    /**
     * 根据id查询变更详情
     *
     * @param baseBuildInfo 变更类型id
     * @return
     */
    @RequestMapping("/getBuildingReq")
    @LogRecord(description = "查询结构变更的列表", operationUnit = LogOperationUnit.BASE_REGION_INFO, operationType = LogOperationType.SELECT)
    public PageInfo<BaseBuildInfo> getBuildingReq(Page page, BaseBuildInfo baseBuildInfo) {
        return baseBuildInfoService.getBuildingReq(page, baseBuildInfo);
    }

    @RequestMapping("/getInfoBuild")
    @LogRecord(description = "查询自然幢基本信息", operationUnit = LogOperationUnit.BASE_REGION_INFO, operationType = LogOperationType.SELECT)
    public BaseBuildInfo getInfoBuild(String id) {
        return baseBuildInfoService.getInfoBuild(id);
    }
}
